	//构造函数
	function MultipleSelect(mSelectId, data) {
		//相关id和数据
		this.mSelectId = mSelectId;
		this.opened = false;
		if (data && data != null && data != "" && data != "null")
			this.value = data.split(",");
		else
			this.value = null;

		//相关对象
		this.obj = document.getElementById(mSelectId);
		this.objDiv = document.getElementById(this.mSelectId + ".div");
		this.objDesc = document.getElementById(this.mSelectId + ".desc");
		this.objButton = document.getElementById(this.mSelectId + ".button");
		this.children = this.objDiv.getElementsByTagName("input");
		
		//动态获取选项的相关参数
		this.url = this.obj.getAttribute("url");
		this.content = this.obj.getAttribute("content");
		
		if (this.url == null && this.content != null) {
			//需要根据个各项目定义的通用获取option的链接
			this.url = "/content.xml?content=" + this.content;
		}
		this.method = this.obj.getAttribute("method");
		this.valueProperty = this.obj.getAttribute("valueProperty");
		this.textProperty = this.obj.getAttribute("textProperty");
				
		//记录dependon的参数
		this.param = {};
		this.free = {};
		this.removeParam = function (paramName) {
			if (paramName && paramName != "")
				delete this.param[paramName];
		};
		this.setParam = function (paramName, paramValue) {	
			if (paramName && paramName != "" && paramValue && paramValue != "") {
				this.param[paramName] = paramValue;
			}	
		};
		this.getParam = function () {
			return hashToParam(this.param);
		}
		this.isFree = function () {
			return hashToBool(this.free);
		}
		
		
		//事件
		//当按delete时得清空
		var oThis = this;
		var deleteKeyDown = function (event) {
			event.returnValue = false;
			if (event.keyCode == 46) {			
				oThis.multipleClear();
			}
			return false;
		}
		//按钮
		var buttonClick = function () {
			if (!oThis.opened)
				oThis.multipleOpen();
			else
				oThis.multipleClose();
		}
		//鼠标离开div
		var mouseLeave = function () {
			oThis.multipleClose();
		}
		//IE
		if (document.all) {
			this.objDesc.attachEvent("onkeydown", deleteKeyDown);
			this.objButton.attachEvent("onclick", buttonClick);
			this.objDiv.attachEvent("onmouseleave", mouseLeave);
		//FireFox
		} else {
			this.objDesc.addEventListener("keydown", deleteKeyDown, false);
			this.objButton.addEventListener("click", buttonClick, false);
			this.objDiv.addEventListener("mouseleave", mouseLeave, false);
		}

		this.multipleInit();
	}
	
	//关闭层
	MultipleSelect.prototype.multipleClose = function () {
		//关闭
		this.opened = false;		
		this.objDiv.style.display = "none";
		
		//清空
		var oldValue = this.obj.value;
		this.objDesc.value = "";
		this.obj.value = "";
		
		//重新赋值
		for (i = 0;i < this.children.length;i ++) {
			if (this.children[i].checked) {
				this.objDesc.value = this.objDesc.value + "," + this.children[i].nextSibling.nodeValue;
				this.obj.value = this.obj.value + "," + this.children[i].value;
			}
		}
		this.obj.value = this.obj.value.substring(1);
		this.objDesc.value = this.objDesc.value.substring(1);
		
		//改变值，以及触发一系列事件
		if (this.obj.value != oldValue) {
			this.value = (this.obj.value == "")?null:this.obj.value.split(",");
		}		
		if (typeof this.obj.onchange == "function" && this.obj.value != oldValue) {
			this.obj.onchange();
		}
		if (typeof this.onchange == "function" && this.obj.value != oldValue) {
			this.onchange();
		}
	}
	
	//打开层
	MultipleSelect.prototype.multipleOpen = function (){		
		//置打开的标志
		this.opened = true;
		
//滚动定位xy
//		var sLeft = 0;
//		var sTop = 0;
//		if (document.body) {
//			sLeft = document.body.scrollLeft;
//			sTop = document.body.scrollTop;
//		}

		//定位层的xy
		var dTop = posLib.getBoundingClientBottom(this.objDesc);
		var dLeft = posLib.getBoundingClientLeft(this.objDesc);

		this.objDiv.style.left = dLeft;
		this.objDiv.style.top = dTop;
		this.objDiv.style.display = "block";
	}
	
	
	//初始化控件
	MultipleSelect.prototype.multipleInit = function () {
		if (!this.value) return false;		
		this.opened = false;
			
		this.objDiv.style.display = "none";
		this.obj.value = "";
		this.objDesc.value = "";
						
		for (i = 0;i < this.value.length;i ++) {
			for (j = 0; j < this.children.length; j++) {
			    if (this.children[j].value == this.value[i]) {
			        this.children[j].checked = true;
					this.objDesc.value = this.objDesc.value + "," + this.children[j].nextSibling.nodeValue;
					this.obj.value = this.obj.value + "," + this.children[j].value;
					break;
			    }
			}
		}
		this.obj.value = this.obj.value.substring(1);
		this.objDesc.value = this.objDesc.value.substring(1);
		return true;
	}
	
	//清空已经选择得值
	MultipleSelect.prototype.multipleClear = function () {

		var oldValue = this.obj.value;
		this.obj.value = "";
		this.objDesc.value = "";
		if (this.children) {
			for (i = 0; i < this.children.length; i++) {
				this.children[i].checked = false;
			}
		}
		
		//改变值，以及触发一系列事件
		if (this.obj.value != oldValue) {
			this.value = null;
		}		
		if (typeof this.obj.onchange == "function" && this.obj.value != oldValue) {
			this.obj.onchange();
		}
		if (typeof this.onchange == "function" && this.obj.value != oldValue) {
			this.onchange();
		}
	}
	

	//清空选项
	MultipleSelect.prototype.clearOption = function () {
		if (typeof this.onOptionUnload == "function") {
			this.onOptionUnload();
		}
		
		if (this.children.length != 0) {
			for (k = this.children.length - 1; k >= 0 ; k --) {
				//移除<br>
				this.objDiv.removeChild(this.children[k].nextSibling.nextSibling);
				//移除选项的文字
				this.objDiv.removeChild(this.children[k].nextSibling);
				//移除input
				this.objDiv.removeChild(this.children[k]);
			}
		}
		//重新给children赋值
		this.children = this.objDiv.getElementsByTagName("input");
		this.obj.value = "";
		this.objDesc.value = "";
	}
	
	//添加新的选项
	MultipleSelect.prototype.addOption = function (value, text) {
		//checkbox
		var optionObj = document.createElement("INPUT");
		//br
		var brObj = document.createElement("BR");
		//文本
		var textObj = document.createTextNode(text);
		//optionObj.name = "a1";
		optionObj.type = "CHECKBOX";
		optionObj.value = value;
						
		//添加
		this.objDiv.appendChild(optionObj);
		this.objDiv.appendChild(textObj);
		this.objDiv.appendChild(brObj);
		
		//初始化选的值
		if (this.value) {
			for (i = 0;i < this.value.length;i ++) {
			    if (value == this.value[i]) {
			    	optionObj.checked = true;
			    	if (this.objDesc.value == "")
			    		this.objDesc.value = text;
			    	else
			    		this.objDesc.value = this.objDesc.value + "," + text;
			    	
			    	if (this.obj.value == "")
				    	this.obj.value = value;
			    	else
						this.obj.value = this.obj.value + "," + value;
						
			    	break;
			    }
			}
		}
						
		//刷新children
		this.children = this.objDiv.getElementsByTagName("input");
	}


	//获取选项
	MultipleSelect.prototype.fetchOption = function () {
		//url空，表示改select控件不是需要动态改变可选项的
		if (this.url == null) return;
		//处理带入的参数
		var fp = this.getParam();
		var fu = (fp && fp != null)?this.url + fp:this.url;
		
		//通过http提交请求
		var http = new HttpObject();
		var ret = null;
		if (this.method == 'POST')
			ret = http.httpPostReturnMaps(this.url, fp);
		else
			ret = http.httpGetReturnMaps(fu);
			
		//处理获取的数据
		if (isValid(this.valueProperty) && isValid(this.textProperty)) {
			//清除现有选项
			this.clearOption();
			//新增选项
			for (var i = 0; i < ret.length; i ++) {
				var v = ret[i][this.valueProperty];
				var t = ret[i][this.textProperty];	
				this.addOption(v, t);
			}
				
			if (typeof this.onOptionLoad == "function") {
				this.onOptionLoad();
			}
		}
	}
	
	//depend
	MultipleSelect.prototype.dependOn = function (dependOnId, weakDepend, dependParam) {
		var obj = this;
		
		var dependObj = document.getElementById(dependOnId);
		if (dependObj) {
			var change = function () {
				//以下是和控件相关的方法
				//如果依赖的控件值不为空
				if (dependObj.value && dependObj.value != "") {
					//允许改依赖开锁
					obj.free[dependOnId] = true;
					//参数带入
					if (dependParam) {
						obj.setParam(dependParam, dependObj.value);
					} else {
						obj.setParam(dependObj.name, dependObj.value);
					}
					//获取选项
					if (obj.isFree())
						obj.fetchOption();
				
				//如果依赖的控件值空
				} else {
					if (dependParam) {
						obj.removeParam(dependParam);
					} else {
						obj.removeParam(dependObj.name);
					}
					
					//如果弱依赖关系，那么则获取选项
					if (weakDepend) {
						obj.free[dependOnId] = true;
						if (obj.isFree())
							obj.fetchOption();
					//不是弱依赖关系，那么清除所有选项	
					} else {
						obj.free[dependOnId] = false;
						obj.clearOption();
					}
				}
			}
			//IE
			if (document.all)
				dependObj.attachEvent("onchange", change);
			//FireFox
			else
				dependObj.addEventListener("change", change, false);
			change();
		}
	}



